<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加角色和授权</title>
<meta name="renderer" content="webkit">	
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
<meta name="apple-mobile-web-app-status-bar-style" content="black">	
<meta name="apple-mobile-web-app-capable" content="yes">	
<meta name="format-detection" content="telephone=no">	
<link rel="stylesheet" type="text/css" href="/bsc/static/common/layui/css/layui.css" media="all">
<link rel="stylesheet" type="text/css" href="/bsc/static/common/bootstrap/css/bootstrap.css" media="all">
<link rel="stylesheet" type="text/css" href="/bsc/static/common/global.css" media="all">
<link rel="stylesheet" type="text/css" href="/bsc/static/css/personal.css" media="all">
</head>
<body>
<section class="layui-larry-box">
	<div class="larry-personal" >
		<div class="larry-personal-body clearfix changepwd"  style="width: 350px">
				<div class="layui-form-item">
					<label class="layui-form-label">角色名称</label>
					<div class="layui-input-block">  
					  	<input type="text" name="role_name" id="role_name"  autocomplete="off"  class="layui-input" value="" placeholder="请输入角色名称">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">备注</label>
					<div class="layui-input-block">
						<textarea  value="" class="layui-textarea" name="role_remark" id="role_remark"></textarea>
					</div>
				</div>
				<div class="layui-form-item change-submit">
					<div class="layui-input-block">
						
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
				<div  style="position:absolute; left:380px;top:100px;">
				    <button type="reset" onclick="checkAll()"  class="layui-btn layui-btn-primary" >点击全选</button>
				    <br/><br/>
				    <button class="layui-btn" onclick="add()" lay-filter="demo1">立即提交</button>
				</div>
				
				<div class="layui-form-item" style="position:absolute; left:500px;top:0px;">
		            <ul id="treeDemo" class="ztree"  style="background-color: #FFFFFF;"></ul>
		       </div>
		</div>
	</div>
</section>
<link rel="stylesheet" href="/bsc/static/ztree/css/demo.css" type="text/css">
<link rel="stylesheet" href="/bsc/static/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="/bsc/static/ztree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/bsc/static/ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="/bsc/static/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
<script type="text/javascript" src="/bsc/static/ ztree/js/jquery.ztree.exedit-3.5.min.js"></script>
	<script type="text/javascript">
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};
		var zNodes =${json};
		$(document).ready(function() {
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			/* var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			  //将现有节点全部选中（不包括还没有展开的节点）
			  treeObj.checkAllNodes(false); */
		});
		function checkAll(){
			var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
			  //将现有节点全部选中（不包括还没有展开的节点）
			  treeObj.checkAllNodes(true);
		}
		function add(){
			//初始化树
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			var nodes=zTree.getCheckedNodes(true);  //获取复选框改变的值
			var array=[];
			$.each(nodes,function(index,n){
				array.push(n.id);
			});
			var data=array.join(",");
			var role_name=$("#role_name").val();
			var role_remark=$("#role_remark").val();
			alert(role_name);
			$.ajax({
			    	url:"/bsc/systemrole/save",
			    	type:"post",
			    	data:{"role_name":role_name,"role_remark":role_remark,"data":data},
			    	success:function(msg){
			    		alert("添加成功")
			    		parent.location.reload();
			    	}
			     });   
		} 
	</script>
</body>
</html>